package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.CompanyMapper;
import com.wanmait.recruit.pojo.Company;
import com.wanmait.recruit.pojo.Person;
import com.wanmait.recruit.service.CompanyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("companyService")
@Transactional(rollbackFor = Exception.class)
public class CompanyServiceImpl implements CompanyService {

    @Resource
    CompanyMapper companyMapper;

    @Override
    public PageInfo<Company> search(Integer pageNum,Integer pageSize,String companyName,String city,Integer scopeMin,Integer scopeMax){
        PageHelper.startPage(pageNum,pageSize);
        List<Company> companies = companyMapper.findSelective(companyName,city,scopeMin,scopeMax);
        PageInfo<Company> pageInfo = new PageInfo<>(companies);

        return pageInfo;
    }

    @Override
    public void insert(Company object) {

        companyMapper.insertSelective(object);
    }

    @Override
    public void delete(Company object) {

    }

    @Override
    public void update(Company object) {
        companyMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public PageInfo<Company> search(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Company> companies = companyMapper.findAll();
        PageInfo<Company> pageInfo = new PageInfo<>(companies);
        return pageInfo;
    }

    @Override
    public Company findByCompanyName(String companyName) {
        return companyMapper.findByCompanyName(companyName);
    }

    @Override
    public Company findByPerson(Person person) {
        return null;
    }

    @Override
    public Company findById(Integer id) {
        //return companyMapper.selectByPrimaryKey(id);
        return  companyMapper.findById(id);
    }
}
